<template>
  <view>
    <!-- 选择收货地址 -->
    <view class="choose-box" v-if="JSON.stringify(address)===('{}'||'undefined')">
      <button type="primary" size="mini" @click="chooseAddress">选择收货地址+</button>
    </view>
    <!-- 收货地址信息 -->
    <view class="address-message" @click="chooseAddress" v-else>
      <view class="top-descs">
        <view class="left-consignee">
          收货人：{{address.userName}}
        </view>
        <view class="right-phone">
          <view class="phone">
            电话：{{address.telNumber}}
          </view>
          <uni-icons type="arrowright" size="16"></uni-icons>
        </view>
      </view>
      <view class="bottom-address">
        <view class="address-title">
          收货地址：
        </view>
        <view class="address-detail">
          {{addressStr}}
        </view>
      </view>
    </view>
    <!-- 底部边框线 -->
    <image class="address-border" src="/static/cart_border@2x.png"></image>
  </view>
</template>

<script>
  import {
    mapState,
    mapMutations,
    mapGetters
  } from 'vuex'
  export default {
    name: "my-address",
    data() {
      return {};
    },
    computed: {
      ...mapGetters('m_user', ['addressStr']),
      ...mapState('m_user', ['address'])
    },
    methods: {
      ...mapMutations('m_user', ['updateAddress']),
      // 选择收货地址
      async chooseAddress() {
        const [err, succ] = await uni.chooseAddress().catch(err => err)
        if (!err && succ.errMsg === "chooseAddress:ok") {
          this.updateAddress(succ)
        }
      }
    }
  }
</script>

<style lang="scss">
  // 选择收获地址
  .choose-box {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 90px;
  }

  // 收货地址信息
  .address-message {
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 90px;
    padding: 0 5px;
    font-size: 24rpx;

    // 顶部联系人信息
    .top-descs {
      display: flex;
      justify-content: space-between;

      .left-consignee {}

      .right-phone {
        display: flex;
      }
    }

    // 底部地址信息
    .bottom-address {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      margin-top: 10px;

      .address-title {
        white-space: nowrap;
      }
    }
  }

  // 地址边框线
  .address-border {
    display: block;
    width: 100%;
    height: 10rpx;
  }
</style>
